package mianshi;

import niuke.TreeNode;

/**
 * description:
 * author:张腾
 * date:2021-07-21
 */
public class _04_05 {
    TreeNode pre;
    public boolean isValidBST(TreeNode root) {
        if (root == null) return true;
        return inOrder(root);
    }
    public boolean inOrder(TreeNode root){
        if (root.left!=null) {
            if (!inOrder(root.left)) return false;
        }
        if (pre!=null && pre.val>=root.val) return false;
        pre = root;
        if (root.right!=null) {
            if (!inOrder(root.right)) return false;
        }
        return true;
    }

}
